package com.smcaiot.jftorg.domain.user;

import cn.hutool.core.util.StrUtil;
import com.smcaiot.core.exception.DomainException;
import com.smcaiot.core.stereotype.Aggregate;
import com.smcaiot.core.stereotype.Default;
import com.smcaiot.jftorg.domain.org.Org;
import com.smcaiot.jftorg.domain.org.OrgId;
import lombok.Data;

/**
 * @Author: cz
 * @Date: 2023/9/26
 * @Description:
 */
@Data
@Aggregate
public class User extends Org {
    /**
     * 角色
     */
    private UserRole role;

    public User(String role) {
        super();
        initRole(role);
    }

    @Default
    public User(OrgId warningSignal, String name, OrgId deptId, String role) {
        super(deptId, warningSignal, name);
        initRole(role);
    }

    private void initRole(String role) {
        DomainException.isTrue(StrUtil.isNotBlank(role), "角色类型不能为空");
        this.role = UserRole.getByCode(role);
    }

    public boolean isKSLeader() {
        return getRole().isKSLeader();
    }

    public boolean isFJLeader() {
        return getRole().isFJLeader();
    }

    public boolean isPolice() {
        return getRole().isPolice();
    }

    public boolean isFujing() {
        return getRole().isFujing();
    }
}
